<?php

/**
 * Description of selectBook
 *
 * @author nahuel.lema
 */
if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Log extends CI_Controller {
    
    function __construct() {
        parent::__construct();
        $this->load->library('session');
    }

    public function in () {
        if ($usuario = Usuario::isValido($_POST['email'], $_POST['pass'])) {
            $newdata = array(
                'username' => $usuario->toString(),
                'logged_in' => TRUE
            );
            $this->session->set_userdata( array('logged_in' => TRUE, 'usuario_id'=>$usuario->id));
            redirect('panel', 'refresh');
        } else {
            redirect('ingresar', 'refresh');
        }
    }
    
    public function out () {
        $this->session->sess_destroy();
        redirect('ingresar', 'refresh');
    }
    
    public function to ($id) {
        if ($usuario = Doctrine::getTable('usuario')->find($id)) {
            $newdata = array(
                'username' => $usuario->toString(),
                'logged_in' => TRUE
            );
            $this->session->set_userdata( array('logged_in' => TRUE, 'usuario_id'=>$usuario->id));
            redirect('panel', 'refresh');
        } else {
            redirect('ingresar', 'refresh');
        }
    }
}
?>
